
from game.fov import *
from game.state.gamestate import *
import pygame
from pygame.locals import *


class WaitState(GameState):
    def __init__(self, data):
        GameState.__init__(self, data)

    def update(self, ms):
        dat = self.data

        #if the main character is not the front of the schedule, then keep going until it is
        c_char = dat.sched_mgr.peek()
        while c_char != dat.main_char:
            c_char.update_ai(dat)
            c_char = dat.sched_mgr.peek()
        return 1

    def event(self, evt):
        dat = self.data
        if evt.type == KEYDOWN:
            mov = self.get_dir(evt.key)
            if mov != 0:
                pp = dat.main_char.pos()
                dat.act_mgr.perform("move", dat, pp, [mov])
            else:
                if evt.key == K_o:
                    dat.state_mgr.push_state("open")
                elif evt.key == K_c:
                    dat.state_mgr.push_state("close")
                elif evt.key == K_COMMA:
                    dat.act_mgr.perform("pickup", dat, dat.main_char.pos(), [(0,0)])
                    dat.gui.inv_mgr.rebuild()
                elif evt.key == K_PERIOD:
                    dat.act_mgr.perform("check", dat, dat.main_char.pos(), [(0,0)])
                else:
                    pass

            dat.gui.msg_mgr.rebuild()

        return 1

    def draw(self, ms):
        self.normal_draw(ms)